package com.heima.behavior.listen;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.service.ApFollowBehaviorService;
import com.heima.common.message.FollowBehaviorConstants;
import com.heima.model.behavior.dtos.FollowBehaviorDto;
import com.heima.model.behavior.pojos.ApFollowBehavior;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @作者 itcast
 * @创建日期 2021/2/4 10:07
 **/
@Component
@Slf4j
public class FollowBehaviorListener {
    @Autowired
    ApFollowBehaviorService apFollowBehaviorService;
    @KafkaListener(topics = FollowBehaviorConstants.FOLLOW_BEHAVIOR_TOPIC)
    public void followBehaviorHandle(String dtoJson){
        log.info("FollowBehaviorListener 被触发 参数为==>{}",dtoJson);
        if (StringUtils.isNotBlank(dtoJson)) {
            FollowBehaviorDto dto = JSON.parseObject(dtoJson, FollowBehaviorDto.class);
            apFollowBehaviorService.saveFollowBehavior(dto);
        }
    }
}
